package com.example.dao;

import com.example.bean.Student;
import com.example.util.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class StudentDeleteDaoImp implements StudentDeleteDao{

    @Override
    public int getStudentDelete(Student student) {
        Connection connection=null;
        PreparedStatement preparedStatement=null;
        try {
            //1.建立连接
            connection= DBUtil.getConnection();
            //2.编写SQL语句
            String sql="delete from s_user where sname=?";
            //3.预处理对象
            preparedStatement = connection.prepareStatement(sql);
            //4.设置占位符
            preparedStatement.setString(1,student.getSname());
            //5.受影响的行数
            int i = preparedStatement.executeUpdate();
            return i;
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            //6.释放相关的资源
            try {
                DBUtil.closeResource(connection,preparedStatement);
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return 0; //表示删除失败

    }
}
